package pt.inescid.components.policyengine.heimdall.pdp.base;

import pt.inescid.components.policyengine.heimdall.commons.TimeUtilities;
import pt.inescid.components.policyengine.heimdall.pap.base.ReevaluationDefinition;

public class ReevaluationInstance {

	private ReevaluationDefinition definition;

	private ModelInstance startModel;
	
	private RuleInstance stop;
	
	private long lastReevaluationTime = 0;
	private long every = 0;
	
	
//  ----------------------------------------------------------
//  ------------------------   constructor   ------------------------
//  ----------------------------------------------------------
	public ReevaluationInstance(ReevaluationDefinition definition, 
			ModelInstance currentModel) {
		this.definition = definition;
		this.startModel = currentModel;
		
		this.lastReevaluationTime = TimeUtilities.getCurrentTime();
		this.every = TimeUtilities.parseTimeQty(
				definition.getEvery());
		
		stop = RuleInstance.getInstance(definition.getStop(),
				currentModel, null);
	}


	
	
		
	
	/* ===========================================================
	==============================================================
	=============                    =============================
	=============      stopsReevaluation       =============================
	=============                    =============================
	==============================================================
	=========================================================== */
	public boolean stopsReevaluation(ModelInstance currentModel) {
		
		if (stop != null) {
			return (((Boolean) stop.evaluate(currentModel,
					false)).
					booleanValue());
		}
		else {
			return (true);
		}
	} // stopsReevaluation
		
		

	
	
	public ReevaluationDefinition getDefinition() {
		return definition;
	}


	public RuleInstance getStop() {
		return stop;
	}


	public void setDefinition(ReevaluationDefinition definition) {
		this.definition = definition;
	}


	public void setStop(RuleInstance stop) {
		this.stop = stop;
	}


	public long getEvery() {
		return every;
	}


	public long getLastReevaluationTime() {
		return lastReevaluationTime;
	}


	public ModelInstance getStartModel() {
		return startModel;
	}


	public void setEvery(long every) {
		this.every = every;
	}


	public void setLastReevaluationTime(long lastReevaluationTime) {
		this.lastReevaluationTime = lastReevaluationTime;
	}


	public void setStartModel(ModelInstance startModel) {
		this.startModel = startModel;
	}


	
	
	
}; // ReevaluationInstance
